package me.sealer.plugins.util;

import java.io.File;
import java.util.List;

/**
 * @author sealer
 * @date 2018/06/06.
 * @email 1178884049@qq.com
 */
public class FileCountUtil {
    /**
     * 判断该文件是否统计
     *
     * @param includes
     * @param file
     * @return
     */
    public static boolean isFileValid(String[] includes, File file) {
        for (String include : includes) {
            if (file.getName().endsWith("." + include)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 统计整理dir目录下的所有文件
     *
     * @param collected
     * @param dir
     * @param includes
     */
    public static void collectFiles(List<File> collected, File dir, String[] includes) {
        if (dir.isFile()) {
            if (FileCountUtil.isFileValid(includes, dir)) {
                collected.add(dir);
            }
        } else {
            for (File subFile : dir.listFiles()) {
                collectFiles(collected, subFile, includes);
            }
        }
    }
}
